
//
//  CheckStatusViewController.m
//  DaJiang
//
//  Created by sally on 16/10/7.
//  Copyright © 2016年 jiniu. All rights reserved.
//

#import "CheckStatusViewController.h"
#import "DateUtil.h"
#import "ExpertInfoEditViewController.h"

@interface CheckStatusViewController ()

@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (weak, nonatomic) IBOutlet UIButton *modifyBtn;

@end

@implementation CheckStatusViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  [self initControl];
  [self initData];
}

#pragma mark 初始化控件
- (void)initControl {
  self.title = @"成为专家";

  NSString *statusText;
  NSInteger firstLineLength = 0;

  switch (self.statusModel.data.application_state) {
    case 0: //申请中
      self.checkStatus = CheckStatus_Ing;
      break;
    case 1: //通过
      break;
    case 2: //拒绝
      self.checkStatus = CheckStatus_Fail;
      break;
    default:
      break;
  }

  //审核中
  if (self.checkStatus == CheckStatus_Ing) {
    NSString *date;
    if (self.statusModel) {
      date = [DateUtil getFormatTime:self.statusModel.updated_at];
    } else {
      //获取当前时间
      NSDate *currentDate = [NSDate date];
      NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
      [dateFormatter setDateFormat:@"YYYY-MM-dd"];
      date = [dateFormatter stringFromDate:currentDate];
    }
    statusText = [NSString stringWithFormat:@"您提交的申请正在审核中\n\n%@", date];
    firstLineLength = 11;
    self.modifyBtn.hidden = YES;
  }
  //审核未通过
  else {
    NSString *date = [DateUtil getFormatTime:self.statusModel.updated_at];
    statusText = [NSString stringWithFormat:@"您提交的申请，没能通过审核\n\n%@\n\n%@", self.statusModel.data.reject_reason, date];
    firstLineLength = 13;
    self.modifyBtn.hidden = NO;
  }

  NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:statusText];
  [attrStr addAttribute:NSFontAttributeName value:GFontWithSize(GSmallFontSize) range:NSMakeRange(firstLineLength, statusText.length - firstLineLength)];
  self.statusLabel.attributedText = attrStr;
}

#pragma mark 初始化数据
- (void)initData {
}

#pragma mark 重写返回功能
- (BOOL)navigationShouldPopOnBackButton {
  [self.navigationController popToRootViewControllerAnimated:YES];
  return NO;
}

#pragma mark - action
#pragma mark 点击修改
- (IBAction)actionOnModify:(id)sender {
  ExpertInfoEditViewController *vc = [[ExpertInfoEditViewController alloc] init];
  [self.navigationController pushViewController:vc animated:YES];
}

@end
